home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- File : UnixFiles.h - Macintosh implementation of some things
- useful for handling UN*X files and such.
- Author : Matthias Neeracher <neeri@iis.ethz.ch>
- Started : 28May91 Language : MPW C
- 28May91 MN Created
- 28May91 MN isatty()
- 09Dec91 MN Radical overhaul
- 15Dec91 MN mkdir(), FSpUp, FSpDown
- Last : 15Dec91
-
- Copyright (c) 1991, 1992 Matthias Neeracher
-
- You may distribute under the terms of either the GNU General Public
- License or the Artistic License, as specified in the README file.
-
- *********************************************************************/
-
- /* Pathnames Macintosh-style (with ':' as a directory separator).
- This code is not A/UX compatible and doesn't know about System 7 aliases
- (because it's author doesn't know, either :-) and AppleTalk access
- rights (too complicated right now).
-
- Unix interfaces are generally built after their description in the
- SunOS 3.0 manpages
- */
-
- /**************** Routines dealing with paths ********************************/
-
- #include <Types.h>
- #include <Files.h>
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /* None of the following routines depend on System 7 running. */
-
- /* Convert a working directory & file name into a FSSpec. */
- OSErr WD2FSSpec(short wd, ConstStr31Param name, FSSpec * desc);
-
- /* Convert a FSSpec into a full pathname. */
- char * FSp2FullPath(const FSSpec * desc);
-
- /* Works like FSp2FullPath, but creates a *relative* pathname if the object
- is contained in the current directory.
- */
- char * FSp2RelPath(const FSSpec * desc);
-
- /* Call GetCatInfo for file system object. */
- OSErr FSpCatInfo(const FSSpec * desc, CInfoPBRec * info);
-
- /* Is Object a file ? */
- Boolean IsFile(const CInfoPBRec * info);
-
- /* Return FSSpec of (vRefNum, parID) */
- OSErr FSpUp(FSSpec * desc);
-
- /* Return FSSpec of file in directory denoted by desc */
- OSErr FSpDown(FSSpec * desc, ConstStr31Param name);
-
- /* Return FSSpec of nth file in directory denoted by (vRefNum, parID) */
- OSErr FSpIndex(FSSpec * desc, short n);
-
- /* Convert a pathname into a file spec. */
- OSErr Path2FSSpec(const char * path, FSSpec * desc);
-
- #ifdef __cplusplus
- }
- #endif
-
- /*************** Stat related stuff *****************************************/
-
- #include <time.h>
-
- typedef unsigned short u_short;
- typedef long off_t;
- typedef short dev_t;
- typedef long ino_t;
-
- /* mode information */
-
- #define S_IFMT 0170000
- #define S_IFDIR 0040000
- #define S_IFCHR 0020000
- #define S_IFBLK 0060000
- #define S_IFREG 0100000
- #define S_IFLNK 0120000
- #define S_IFSOCK 0140000
-
- #define S_ISUID 0004000
- #define S_ISGID 0002000
- #define S_ISVTX 0001000
- #define S_IREAD 0000400
- #define S_IWRITE 0000200
- #define S_IEXEC 0000100
-
- /* Group and others permission is same as owner */
-
- struct stat {
- dev_t st_dev; /* Set to vol. refNum. */
- ino_t st_ino; /* Set to file ID */
- u_short st_mode;
- short st_nlink; /* Always 1 */
- short st_uid; /* Set to 0 */
- short st_gid; /* Set to 0 */
- dev_t st_rdev; /* Set to 0 */
- off_t st_size;
- time_t st_atime; /* Set to st_mtime */
- time_t st_mtime;
- time_t st_ctime;
- long st_blksize;
- long st_blocks;
- };
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- int stat(char * path, struct stat * buf);
- int lstat(char * path, struct stat * buf);
- int fstat(int fd, struct stat * buf);
- int isatty(int);
-
- #ifdef __cplusplus
- }
- #endif
-
- /*************** Directory related stuff *****************************************/
-
- typedef struct dir DIR;
-
- #define MAXNAMLEN 31
-
- typedef struct direct {
- short d_namelen;
- char d_name[MAXNAMLEN + 1];
- } direct;
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- DIR * opendir(char * name);
- direct * readdir(DIR * dirp);
- long telldir(DIR * dirp);
- void seekdir(DIR * dirp, long loc);
- void rewinddir(DIR * dirp);
- void closedir(DIR * dirp);
- int chdir(char * path);
- int mkdir(char * path);
- #ifdef __cplusplus
- }
- #endif
-